package org.java.dao;

import org.java.entity.User;
import org.java.util.JdbcUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;


public class UserDao {
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(JdbcUtil.getDs());

    public List<User> getList() {
        String sql ="select * from user";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(User.class));
    }

    //冻结账户
    public void frozen(String id) {
        String sql ="UPDATE USER SET state=0 WHERE uid=?";
        jdbcTemplate.update(sql,id);
    }

    //启用账户
    public void enable(String id) {
        String sql ="UPDATE USER SET state=1 WHERE uid=?";
        jdbcTemplate.update(sql,id);
    }

    //修改
    public void update(String id, String name, String pwd, String number, Integer state) {
        String sql ="UPDATE USER SET uname=?,upwd=?,unumber=?,state=? WHERE uid=?";
        jdbcTemplate.update(sql,name,pwd,number,state,id);
    }
}
